package com.cindata

import com.cindata.dictionary.*

class AccountProject
{
    String name
    // 项目名称
    City city
    // 城市
    String address
    // 项目地址
    String entryStatus
    // 入围状态
    String buildingstructure
    // 建筑结构
    String preSalePermitNumber
    // 预售证编号
    Date completionDate
    // 竣工验收
    Date deliveryDate
    // 交房时间

    Workflow workflow
    ProjectRiskType riskType

    Date createdDate = new Date()
    Date modifiedDate = new Date()
    User user
    User createBy
    User modifyBy

    static belongsTo = [account: Account]
    static hasMany = [buildings: AccountProjectBuilding]
    static mapping = {
        autowire true
    }
    static constraints = {
        name maxSize: 50, nullable: true, blank: true, comment: '项目名称'
        city nullable: true, blank: true, comment: '城市'
        address maxSize: 150, nullable: true, blank: true, comment: '项目地址'
        entryStatus maxSize: 50, nullable: true, blank: true
        buildingstructure maxSize: 50, nullable: true, blank: true
        preSalePermitNumber maxSize: 50, nullable: true, blank: true
        completionDate nullable: true, blank: true
        deliveryDate nullable: true, blank: true

        createdDate nullable: true, blank: true
        modifiedDate nullable: true, blank: true
        user nullable: true, blank: true
        createBy nullable: true, blank: true
        modifyBy nullable: true, blank: true
        
        workflow nullable: true, blank: true
        riskType nullable: true, blank: true
    }

    def springSecurityService
    def beforeInsert()
    {
        def username = springSecurityService?.getPrincipal()?.username
        createBy = User.findByUsername(username)
    }

    def beforeUpdate()
    {
        modifiedDate = new Date()
        def username = springSecurityService?.getPrincipal()?.username
        modifyBy = User.findByUsername(username)
    }
}
